package cn.tedu.spring.lifecycle;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Controller
public class Life {
    private String name;

    public Life() {
        System.out.println("1.无参构造实例化");
    }
    @Value("张三")
    public void setName(String name) {
        this.name = name;
        System.out.println("2.调用set方法进行属性赋值");
    }
    @PostConstruct
    public void  init(){
        System.out.println("3.执行生命周期初始化");
    }
    @PreDestroy
    public void destory(){
        System.out.println("5.执行生命周期销毁方法");
    }
    @Override
    public String toString() {
        return "Life{" +
                "name='" + name + '\'' +
                '}';
    }
}
